package com.mall.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.PmsProductAttributeCategoryMapper;
import com.mall.model.domain.PmsProductAttributeCategory;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author xyiaao
 * @description 针对表【pms_product_attribute_category(产品属性分类表)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService
public class PmsProductAttributeCategoryApiImpl extends ServiceImpl<PmsProductAttributeCategoryMapper, PmsProductAttributeCategory>
        implements PmsProductAttributeCategoryApi {

    @Autowired
    private PmsProductAttributeCategoryMapper categoryMapper;

    @Override
    public PmsProductAttributeCategory findProductCategoryByName(String name) {
        LambdaQueryWrapper<PmsProductAttributeCategory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PmsProductAttributeCategory::getName,name);
        PmsProductAttributeCategory category = categoryMapper.selectOne(queryWrapper);
        return category;
    }

    @Override
    public void saveProductCategory(PmsProductAttributeCategory pmsProductAttributeCategory) {
        categoryMapper.insert(pmsProductAttributeCategory);
    }

    @Override
    public PmsProductAttributeCategory findProductCategoryById(Long id) {
        PmsProductAttributeCategory pmsProductAttributeCategory = categoryMapper.selectById(id);
        return pmsProductAttributeCategory;
    }

    @Override
    public void deleteCategory(Long id) {
        categoryMapper.deleteById(id);
    }

    @Override
    public Page<PmsProductAttributeCategory> selectByPage(Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<PmsProductAttributeCategory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.isNotNull(PmsProductAttributeCategory::getName);
        Page<PmsProductAttributeCategory> page = new Page<>(pageNum, pageSize);
        Page<PmsProductAttributeCategory> categories = categoryMapper.selectPage(page,queryWrapper);
        return categories;
    }

    @Override
    public void updateCategory(PmsProductAttributeCategory category) {
        categoryMapper.updateById(category);
    }

    @Override
    public List<PmsProductAttributeCategory> selectAll() {
        LambdaQueryWrapper<PmsProductAttributeCategory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.isNotNull(PmsProductAttributeCategory::getName);
        List<PmsProductAttributeCategory> categories = categoryMapper.selectList(queryWrapper);
        return categories;
    }
}




